
#include "mcu_dda_rmsg.h"

#include <stdlib.h>

void DdaRmsg::Merge(Nhead nhead, Ndata* paMsg)
{
	WORD len = 16;
	if (paMsg != NULL && paMsg->DataType()!= NULL_TYPE) {
		len = (WORD)(16 + paMsg->Length());
	}
	_EnsureSize(len);
	memcpy(m_bBuffer, nhead, 16);
	m_len = 16;
	if (paMsg != NULL) {
		Append(paMsg);
	}
	NLENGTH(m_bBuffer) = (WORD)m_len;
}


BOOL DdaRmsg::ExportToFifo(CxNfifo* sendingFifo)
{
	return(sendingFifo->PushNtape(m_bBuffer));
}

BOOL DdaRmsg::ImportFromFifo(CxNfifo* rcvFifo)
{
	WORD nLen = rcvFifo->PeekNextLength();
	if (nLen == 0) {
		return(FALSE);
	}

	_EnsureSize(nLen);
	m_len = rcvFifo->PopNtape(m_bBuffer, m_size);
	return(TRUE);
}

void DdaRmsg::GetHead(Nhead nhead)
{
	memcpy(nhead, m_bBuffer, 16);
}

void DdaRmsg::GetMsg(Ndata* paMsg)
{
	paMsg->Import(m_bBuffer + 16, m_len - 16);
}


WORD DdaRmsg::GetNtype() {

	return NTYPE(m_bBuffer);
}